package com.fjrz.bbxwj.app

import androidx.camera.camera2.Camera2Config
import androidx.camera.core.CameraXConfig
import androidx.multidex.MultiDex
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.SPStaticUtils
import com.module.lemlin.base.BaseApplication
import com.fjrz.bbxwj.entity.UserMe
import rxhttp.RxHttp


class RZApplication : BaseApplication(), CameraXConfig.Provider {

    companion object {
        private const val KEY_HTTP_TOKEN = "token"

        fun token(): String? = SPStaticUtils.getString(TOKEN)

        fun userInfoMe(): UserMe? = try {
            GsonUtils.fromJson(SPStaticUtils.getString(USER_INFO_ME), UserMe::class.java)
        } catch (e: Exception) {
            null
        }
    }

    override fun onCreate() {
        super.onCreate()

        //设置http debug模式
        RxHttp.setDebug(true)
        //设置http公共请求头token
        RxHttp.setOnParamAssembly {
            it.addHeader(KEY_HTTP_TOKEN, token())
        }
        //初始dex
        MultiDex.install(INSTANCE)
    }

    override fun getCameraXConfig(): CameraXConfig {
        return Camera2Config.defaultConfig()
    }
}